package com.project.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.dto.StockTransactionQueryDTO;
import com.project.entity.StockTransactions;
import com.project.mapper.StockTransactionsMapper;
import com.project.result.PageResult;
import com.project.service.StockTransactionsService;
import com.project.vo.StockTransactionListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StockTransactionsServiceImpl extends ServiceImpl<StockTransactionsMapper, StockTransactions> implements StockTransactionsService {
    @Autowired
    private StockTransactionsMapper stockTransactionsMapper;

    /**
     * 分页查询库存流水列表
     *
     * @param stockDto
     * @return
     */
    @Override
    public PageResult<StockTransactionListVO> queryStockTransactionPage(StockTransactionQueryDTO stockDto) {
        Page<StockTransactionListVO> page = new Page<>(stockDto.getPage(), stockDto.getSize());
        Page<StockTransactionListVO> list = stockTransactionsMapper.queryStockTransactionPage(page, stockDto);
        PageResult<StockTransactionListVO> pageResult = new PageResult<>(list.getTotal(), list.getRecords());
        return pageResult;
    }

    /**
     * 根据库存流水ID获取库存流水信息
     *
     * @param id
     * @return
     */
    @Override
    public StockTransactionListVO getStockTransactionById(Integer id) {
        StockTransactionListVO vo = stockTransactionsMapper.getStockTransactionById(id);
        return vo;
    }
}